#pragma once

#include <functional>
#include <utility>

#include <Windows.h>

#include "Event.h"

namespace Otl { namespace Win32
{
	class CThreadpoolWait final
	{
	public:
		explicit CThreadpoolWait(std::function<void()> callback);
		~CThreadpoolWait();

		//CThreadpoolWait(CThreadpoolWait && other) _NOEXCEPT
		//	: m_wait{ std::move(other.m_wait) },
		//	  m_callback{ std::move(other.m_callback) }
		//{
		//	other.m_wait = nullptr;
		//}

		//CThreadpoolWait & operator=(CThreadpoolWait && other) _NOEXCEPT
		//{
		//	m_wait = std::move(other.m_wait);
		//	other.m_wait = nullptr;

		//	m_callback = std::move(other.m_callback);
		//}

		CThreadpoolWait(CThreadpoolWait && other) = delete;
		CThreadpoolWait & operator=(CThreadpoolWait && other) = delete;

		CThreadpoolWait(const CThreadpoolWait &) = delete;
		CThreadpoolWait & operator=(const CThreadpoolWait &) = delete;

		void Set(const CEvent & evt);

	private:
		static VOID CALLBACK WaitCallback(_Inout_ PTP_CALLBACK_INSTANCE instance,
		                                  _Inout_ PVOID context,
		                                  _Inout_ PTP_WAIT wait,
		                                  _In_ TP_WAIT_RESULT waitResult);

		TP_WAIT * m_wait;
		std::function<void()> m_callback;
	};
}}